﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using BussinessObjects;
using BusinessObjects;
using LibraryO2S;
using System.IO;

public partial class controls_admin_MenuFooter : Pages_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        base.removeHGC(divMessage);
        if (!IsPostBack)
            loadData();
    }
    protected void loadData()
    {
        try
        {
            base.OpenConnection();
            string fname = Server.MapPath("../upload/xml/MenuFooter.xml");
            if (!File.Exists(fname))
            {
                divMessage.InnerHtml = O2S_Message.Warning("Hệ Thống", "Chưa có dữ liệu!");
                return;
            }
            DataSet objDS = new DataSet("MenuFooters");
            objDS.ReadXml(Server.MapPath("../upload/xml/MenuFooter.xml"));
            Session.Add("objDS", objDS);
            DataTable objDT = objDS.Tables["MenuFooter"];
            if (objDT != null && objDT.Rows.Count > 0)
            {
                rptData.DataSource = objDT;
                rptData.DataBind();
            }
            else
            {
                rptData.DataSource = null;
                rptData.DataBind();
                divMessage.InnerHtml = O2S_Message.Warning("Hệ Thống", "Chưa có dữ liệu!");
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally { base.CloseConnection(); }
    }
    /// <summary>
    /// ///////////////////////////////////////////Command/////////////////////
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void rptData_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        try
        {
            base.OpenConnection();
            DataSet objDS = (DataSet)Session["objDS"];
            DataTable objDT = objDS.Tables["MenuFooter"];
            string commandName = e.CommandName;
            if (commandName.Equals("del"))
            {
                int no = Convert.ToInt32(e.CommandArgument);
                objDT.Rows.RemoveAt(no - 1);
                objDS.WriteXml(Server.MapPath("../upload/xml/MenuFooter.xml"));
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Xóa thành công .");
            }
            loadData();
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: <br />" + ex.Message);
        }
        finally { base.CloseConnection(); }
    }

    protected void btnViewTrash_Click(object sender, EventArgs e)
    {
        Response.Redirect("default.aspx?module=ViewNewsTrash");
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        if (Request["category"] == "129")
        {
            Response.Redirect("default.aspx?module=NewHomeMenu");
        }
        //else
        //Response.Redirect("default.aspx?module=NewNewsEvent&category=" + );
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //if (txtSearch.Value.Trim() == "")
        //    txtSearch.Value = "Hãy nhập từ khóa để tìm kiếm kết quả nhanh chóng và chính xác nhất!";
        //else
        //    Response.Redirect("Default.aspx?module=viewnews&search=" + txtSearch.Value.Trim());
    }
    private void loadSrcSearch()
    {
    }
}
